package com.talend.support.dashboard.beans;

import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

import org.primefaces.event.ItemSelectEvent;
import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.ChartSeries;

@SuppressWarnings("serial")
@ManagedBean
@RequestScoped
public class BarChart implements Serializable {

	private CartesianChartModel categoryModel = new CartesianChartModel();
	
	ChartSeries open = new ChartSeries();
	
	public BarChart() {
	}

	public void itemSelect(ItemSelectEvent event) {
		FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,
				"Item selected", "Item Index: " + event.getItemIndex()
						+ "Serie Index:" + event.getSeriesIndex());
		FacesContext.getCurrentInstance().addMessage(null, msg);
	}

	public CartesianChartModel getCategoryModel() {
		return categoryModel;
	}

	@PostConstruct
	public void init() {
		

		ChartSeries open = new ChartSeries();
		open.setLabel("Opened");

		open.set("S1", 120);
		open.set("S2", 100);
		open.set("S3", 44);
		open.set("S4", 150);

		ChartSeries close = new ChartSeries();
		close.setLabel("Closed");

		close.set("S1", 52);
		close.set("S2", 60);
		close.set("S3", 110);
		close.set("S4", 135);

		categoryModel.addSeries(open);
		categoryModel.addSeries(close);
	}

}